{% extends 'layout.html' %}

{% block title %}{{ bucketName }}{% endblock %}


{% block breadcrumb %}
  <li>
    <a href="{{ baseHref }}db/{{ dbName}}">Database:</a>
  </li>
  <li class="dropdown">
    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">{{ dbName }}<span class="caret"></span></a>
    <ul class="dropdown-menu">
      {% for db in databases %}
      <li><a href="{{ baseHref }}db/{{ db }}/">{{ db }}</a></li>
      {% endfor %}
    </ul>
  </li>
  <li>
    <a href="{{ baseHref }}db/{{ dbName}}"><span class="glyphicon glyphicon-chevron-right"></span></a>
  </li>
  <li>
    <a href="{{ baseHref }}db/{{ dbName }}/{{ bucketName }}">Bucket:</a>
  </li>
  <li class="dropdown">
    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">{{ bucketName }}<span class="caret"></span></a>
    <ul class="dropdown-menu">
      {% for bucket in buckets %}
      <li><a href="{{ baseHref }}db/{{ dbName }}/gridFS/{{ bucket }}">{{ bucket }}</a></li>
      {% endfor %}
    </ul>
  </li>
{% endblock %}

{% block content %}
  {% if files.length == 0 %}
    <p class="well">
      No files found.
    </p>
  {% else %}

  <div class="table-responsive tableWrapper">
    <table class="table table-striped">
      <thead>
        {% for column in columns %}
          <th>{{ column }}</th>
        {% endfor %}
        <th>Delete</th>
      </thead>
      {% for file in files %}
        <tr onclick="loadFile('{{ file._id | json | safe | url_encode }}')">
        {% for column in columns %}
          <td><div class="tableContent">{{ file[column] | to_display | safe }}</div></td>
        {% endfor %}
          {% if !settings.read_only %}
            <td>
              <div class="col-md-1">
                <form method="POST" action="{{ baseHref }}db/{{ dbName }}/gridFS/{{ bucketName }}/{{ file._id | json | safe | url_encode }}">
                <input type="hidden" name="_method" value="delete">
                <button type="submit" class="btn btn-danger">
                <span class="glyphicon glyphicon-trash"></span>
                </button>
                </form>
              </div>
            </td>
          {% endif %}
        </tr>
      {% endfor %}
    </table>
  </div>

  {% endif %}

{% if !settings.read_only %}
<!--
  <div class="row">
      <div class="col-md-12">
        <h2>Rename Bucket</h2>
        <form method="POST" action="{{ baseHref }}db/{{ dbName }}/{{ bucketName }}" class="well form-inline">
          <input type="hidden" name="_method" value="put">
          <div class="form-group">
            <input class="input-medium span7" type="text" id="bucket" name="bucket" placeholder="{{ bucketName }}">
          </div>
          <button type="submit" class="btn btn-primary pull-right">
            <span class="glyphicon glyphicon-pencil"></span>
            Rename
          </button>
        </form>
      </div>
  </div>
 -->
<div class="row">
  <div class="col-md-12">
    <h2>Add File</h2>
    <form method="POST" action="{{ baseHref }}db/{{ dbName }}/gridFS/{{ bucketName }}/" enctype="multipart/form-data" class="well form-inline">

      <div class="form-group">
        <input type="file" class="input-medium span7" name="filefield">
      </div>

      <button type="submit" class="btn btn-success pull-right">
        <span class="glyphicon glyphicon-upload"></span>
        Upload
      </button>
    </form>
  </div>
</div>
{% endif %}


{% endblock %}
{% block scripts %}
<script src="{{ baseHref }}{{ assets.gridfs.js }}"></script>
{% endblock %}
